/* 
  公共接口
*/
import request from "@/utils/request";
import {
	config
} from "@/common/config.js";
import store from "@/store";

// 单点登陆-获取登陆所需要的信息
export function apiTicketLogin(data) {
	/*  */
	return request({
		url: `${config.ticketURL}?ticket=${data}`,
		method: "get",
	});
}

// 单点登陆-获取登陆所需要的信息
export function apiTicketLoginTest(data) {
	/*  */
	return request({
		url: `/admin/sso/validateTicketTest?ticket=${data}`,
		method: "get",
	});
}
// 单点登陆-获取token
export function apiTicketToken(data) {
	const basicAuth = "Basic " + window.btoa("dog:dog");
	let header = {
		skipToken: true,
		Authorization: basicAuth,
		"Content-Type": "application/json;charset=UTF-8",
	};
	return request({
		url: `/admin/oauth2/token?mobile=${data.mobile}&code=${data.code}&scope=${data.scope}&grant_type=${data.grant_type}`,
		method: "post",
		header: header,
	});
}
// 单点登陆-刷新token
export const apiRefreshToken = (refresh_token) => {
	const grant_type = "refresh_token";
	const scope = "server";
	const FORM_CONTENT_TYPE = "application/x-www-form-urlencoded";
	// 获取当前选中的 basic 认证信息
	const basicAuth = "Basic " + window.btoa("dog:dog");

	return request({
		url: "/admin/oauth2/token",
		headers: {
			skipToken: true,
			Authorization: basicAuth,
			"Content-Type": FORM_CONTENT_TYPE,
		},
		method: "post",
		params: {
			refresh_token,
			grant_type,
			scope
		},
	});
};

//单点登陆-删除token
export function apiDelTicketToken() {
	store.dispatch("setAccessToken", "");
	store.dispatch("setRefreshToken", "");
	return request({
		url: "/admin/token/logout/del",
		method: "post",
	});
}
// 单点登陆-获取用户信息
export function apiGetUserInfo() {
	return request({
		url: "/admin/user/info",
		method: "get",
	});
}

//获取全局接口信息
export function getGlobalInfo() {
	// 调用 request 函数，传入一个配置对象
	return request({
		url: `/irrigation/projectBasicInfo/global`,
		method: "get",
	});
}

//获取高德天气
export function getGdWeather(value) {
	return request({
		url: `/admin/gcCloud/gdWeather`,
		method: "post",
		data: {
			value,
		},
	});
}

// 获取设备列表
export function apiDevicesList(data) {
	return request({
		url: "/irrigation/common/getDevices",
		method: "post",
		data,
	});
}
// 枚举下拉列表
export function apiTypesList(data) {
	return request({
		url: "/irrigation/common/getTypes",
		method: "post",
		data,
	});
}

// 工程下拉列表
export function apiProjectItemsList(data) {
	return request({
		url: "/irrigation/common/getProjectItems",
		method: "post",
		data,
	});
}

// 查询用户列表
export function apiUsersList(data) {
	return request({
		url: "/irrigation/user/page",
		method: "get",
		data,
	});
}

// 灌片分页查询
export function apiProjectAreaList(data) {
	return request({
		url: "/irrigation/projectItem/areaPage",
		method: "post",
		data,
	});
}

// 待办列表统计
export function apiTaskTodo(data) {
	return request({
		url: "/irrigation/dailyLineTask/todo",
		method: "get",
		data,
	});
}

// 流程审批
export function flowRecordAudit(data) {
	return request({
		url: "/irrigation/flowRecord/audit",
		method: "post",
		data,
	});
}